import java.util.HashMap;
import java.util.Map;

public class Num1 {
    public int[] twoSum(int[] nums, int target) {
        if (nums == null){
            return null;
        }

        int[] res = new int[2];
        Map<Integer, Integer> tempMap = new HashMap();
        for (int i = 0; i < nums.length; i++){
            if (tempMap.get(target - nums[i]) != null){
                res[1] = i;
                res[0] = tempMap.get(target - nums[i]);
                return res;
            }

            tempMap.put(nums[i], i);
        }
        return res;
    }

    public static void main(String[] args) {
        Num1 num1 = new Num1();
        int[] nums = {2, 7, 11, 15};
        int[] ansList = num1.twoSum(nums, 18);

        if (ansList != null){
            for (int ans : ansList) {
                System.out.println(ans);
            }
        }
    }
}
